/**
 * There are code generation
 */
package com.neusoft.lohas.modules.ivm.service.order;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.neusoft.lohas.common.persistence.Page;
import com.neusoft.lohas.common.service.BaseService;
import com.neusoft.lohas.modules.ivm.dao.order.DeliveryDetailDao;
import com.neusoft.lohas.modules.ivm.entity.order.DeliveryDetail;

/**
 * 送货单详情Service
 * @author Jackie.Liu
 * @version 2014-12-23
 */
@Component
@Transactional(readOnly = true)
public class DeliveryDetailService extends BaseService {

	@Autowired
	private DeliveryDetailDao deliveryDetailDao;
	
	public DeliveryDetail get(String id) {
		return deliveryDetailDao.get(id);
	}
	
	public Page<DeliveryDetail> find(Page<DeliveryDetail> page, DeliveryDetail deliveryDetail) {
		DetachedCriteria dc = deliveryDetailDao.createDetachedCriteria();
		dc.add(Restrictions.eq(DeliveryDetail.FIELD_DEL_FLAG, DeliveryDetail.DEL_FLAG_NORMAL));
		dc.addOrder(Order.desc("id"));
		return deliveryDetailDao.find(page, dc);
	}
	
	@Transactional(readOnly = false)
	public void save(List<DeliveryDetail> details) {
		deliveryDetailDao.save(details);
	}
	
	@Transactional(readOnly = false)
	public void delete(String id) {
		deliveryDetailDao.deleteById(id);
	}

	public List<DeliveryDetail> findDetailsByOrderId(String id) {
		// TODO Auto-generated method stub
		return deliveryDetailDao.findDetailsByOrderId(id);
	}
	
}
